package cn.fl.product.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.product.service.ISplRlPsnService;
import cn.fl.product.vo.SplRlPsnVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysDictionaryService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.riskctrl.facade.riskctrl.dto.DataResultDTO;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.spl.condition.SplRlPsnQueryCondition;
import fl.spl.facade.spl.constant.SplInfoConstant;
import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @Description: 供应商关联人员信息表 控制层
 */
@Controller
@RequestMapping("/product/splRlPsn")
public class SplRlPsnController extends BaseController {

	/**
	 * PrdSplRlPsn 服务层BEAN
	 */
	@Autowired
	private ISplRlPsnService prdSplRlPsnService;

	@Autowired
	private ISplRlPsnService splRlPsnService;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private ISysDictionaryService sysDictionaryService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		ModelAndView view = new ModelAndView("product/splRlPsn/prdSplRlPsnList");
		view.addObject("splId", splId);
		return view;
	}
	/**
	 * 到详情列表页面
	 */
	@RequestMapping(value = "/toDetailListPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailListPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		ModelAndView view = new ModelAndView("product/splRlPsn/prdSplRlPsnDetailList");
		view.addObject("splId", splId);
		return view;
	}
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String rId = request.getParameter("rId");
		ModelAndView view = new ModelAndView("product/splRlPsn/prdSplRlPsnDetail");
		view.addObject("rId", rId);
		return view;
	}

	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		String rId = request.getParameter("rId");
		ModelAndView view = new ModelAndView("product/splRlPsn/prdSplRlPsnAdd");
		view.addObject("splId", splId);
		view.addObject("rId", rId);
		//证件类型
		List<KeyValueVO> certTypCdList = this.prdSplRlPsnService.searchCertTypCdList();
		view.addObject("certTypCdList", certTypCdList);
		//联系人类型
		List<KeyValueVO> rlTypCDList = this.prdSplRlPsnService.searchRlTypCdList();
		view.addObject("rlTypCDList", rlTypCDList);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initSplRlPsnList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String splId = request.getParameter("splId");
		String isEncrypt = request.getParameter("isEncrypt");
		ListPageVO<SplRlPsnVO> listPage=null;

		if(StringUtils.isEmpty(splId)){
			//新能源事业部 联系人不必填
			if(PropertiesCacheUtils.getProperty(SystemConstant.FL_BUS_XNY_ORG_CD).equals(CurrentThreadContext.getCurrentBuOrgCd())){
				listPage = new ListPageVO<SplRlPsnVO>(new ArrayList<SplRlPsnVO>(), 0);
			}else{
				listPage = new ListPageVO<SplRlPsnVO>(this.setSplRlPsnList(null), 0);
			}
			return listPage;
		}else {
			Pager page = new Pager();
			if (StringUtils.isNotEmpty(currentPage)) {
				page.setCurrentPage(Integer.parseInt(currentPage));
			}

			if (StringUtils.isNotEmpty(currentPage)) {
				page.setEveryPage(Integer.parseInt(pageSize));
			}

			SplRlPsnQueryCondition qc = new SplRlPsnQueryCondition();
			qc.setSplId(Long.valueOf(splId));
			page.setCondition(qc);
			//page.setEveryPage(Integer.MAX_VALUE);//最大数据量

			Pager pager = null;
			if (StringUtils.isNotEmpty(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(isEncrypt)) {
				String roleisEncrypt = this.sysDictionaryService.getRoleisEncrypt();
				if (BaseConstant.IS_YESNO_YES_STR.equals(roleisEncrypt)) {
					pager = this.prdSplRlPsnService.searchListPageWithEncrypt(page);
				} else {
					pager = this.prdSplRlPsnService.searchListPage(page);
				}
			} else {
				pager = this.prdSplRlPsnService.searchListPage(page);
			}
			List<SplRlPsnVO> list = (List<SplRlPsnVO>) pager.getResultList();
			if(PropertiesCacheUtils.getProperty(SystemConstant.FL_BUS_XNY_ORG_CD).equals(CurrentThreadContext.getCurrentBuOrgCd())){
				//新能源事业部 - 无必输联系人
			}else{
				//将未存在的必输联系人添加
				list=this.setSplRlPsnList(list);
			}
			listPage = new ListPageVO<SplRlPsnVO>(list, pager.getTotalCount());
			BaseLogUtils.newWebLogger("初始化供应商联系人列表页面数据.DATA:"+JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeSplRlPsnByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("删除供应商联系人数据,主键参数为空！").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		
		try {
			boolean success = this.prdSplRlPsnService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.newWebLogger("删除供应商联系人数据失败,ID:"+idsList.toString()).setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);

			}
			BaseLogUtils.newWebLogger("删除供应商联系人数据,ID:"+idsList.toString()).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("删除供应商联系人数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("删除供应商联系人数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getSplRlPsnById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("获取供应商联系人数据,主键参数为空.").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		
		try {
			SplRlPsnVO vo = this.prdSplRlPsnService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.newWebLogger("获取供应商联系人数据不存在,ID:"+id).setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);

			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取供应商联系人数据成功,ID:").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("获取供应商联系人数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("获取供应商联系人数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addSplRlPsn(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		SplRlPsnVO entity = new SplRlPsnVO();
		try {
			entity = this.getRequestParamForPrdSplRlPsnAdd(request);
			//TODO ADD PARAM
			Long id = this.prdSplRlPsnService.add(entity);
			result.setData(id);
			BaseLogUtils.newWebLogger("新增供应商联系人数据成功,ID:"+id+".DATA:"+JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增供应商联系人数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("新增供应商联系人数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifySplRlPsn(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		SplRlPsnVO entity = new SplRlPsnVO();
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("修改供应商联系人信息,主键参数为空！.ID:"+id).setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		try {
			entity = this.getRequestParamForPrdSplRlPsnModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.prdSplRlPsnService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.newWebLogger("修改供应商联系人数据失败.DATA:"+JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("修改供应商联系人数据成功.DATA:"+JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("修改供应商联系人数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("修改供应商联系人数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	@RequestMapping(value = "/checkRlPsn.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object checkRlPsnMessage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		String type = request.getParameter("type");//校验类型
		String rlId = request.getParameter("dataId");//联系人ID
		String rlNm = request.getParameter("rlNm");//联系人姓名
		String certNo = request.getParameter("certNo");//联系人身份证号
		String tel = request.getParameter("tel");//联系人电话
		String splId = request.getParameter("splId");//所属供应商ID
		String rlTypCd = request.getParameter("rlTpyCd");//联系人类型
		String applyPsnId = request.getParameter("applyPsnId");
		String splAttrCd = request.getParameter("splAttrCd");// 供应商属性(1:自然人,2:法人)
		if(StringUtils.isEmpty(type)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("参数不完整");
			return result ;
		}
		if(StringUtils.isEmpty(certNo)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("联系人身份证号不能为空");
			return result ;
		}
		if(StringUtils.isEmpty(rlNm)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("联系姓名不能为空");
			return result ;
		}
		if("verify".equals(type)){
			if(StringUtils.isEmpty(splId)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("供应商ID不能为空");
				return result ;
			}
		}else{
			if(StringUtils.isEmpty(tel)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("手机号不能为空");
				return result ;
			}
		}
		if(StringUtils.isEmpty(rlId) && StringUtils.isEmpty(applyPsnId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键ID不能为空");
			return result ;
		}
		HashMap<String, String> dataMap = new HashMap<>();
		dataMap.put("type", type);
		dataMap.put("rlId", rlId);
		dataMap.put("rlNm", rlNm);
		dataMap.put("tel", tel);
		dataMap.put("splId", splId);
		dataMap.put("certNo", certNo);
		dataMap.put("rlTypCd", rlTypCd);
		dataMap.put("splAttrCd", splAttrCd);
		if(StringUtils.isEmpty(applyPsnId) && applyPsnId == "null" ){
			dataMap.put("applyPsnId", "");
		}else{
			dataMap.put("applyPsnId", applyPsnId);
		}
		BaseLogUtils.newWebLogger("数据信息："+JSON.toJSONString(dataMap))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		DataResultDTO checkRlPsn = this.splRlPsnService.checkRlPsn(dataMap);
		BaseLogUtils.newWebLogger("查询结果："+JSON.toJSONString(checkRlPsn))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		result.setSuccess(checkRlPsn.getSuccess());
		result.setInfo(checkRlPsn.getInfo());
		result.setData(checkRlPsn.getData());
		return result ;
	}

	//********************私有方法********************//
	/**
	 * 获取联系人参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private SplRlPsnVO getRequestParamForPrdSplRlPsn(HttpServletRequest request)throws BaseException{
		String splId = request.getParameter("splId");//所属供应商
		
		String rlTypCd = request.getParameter("rlTypCd");//联系人类型
		String rlNm = request.getParameter("rlNm");//姓名
		String certTypCd = request.getParameter("certTypCd");//证件类型
		String certNo = request.getParameter("certNo");//证件号
		String tel = request.getParameter("tel");//联系电话
		String rlRem = request.getParameter("rlRem");//备注
		
		
		//验证参数
		if (StringUtils.isBlank(rlNm)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "联系人姓名不能为空!");
		}
		if(StringUtils.isNotBlank(tel)){
			if(!StringUtils.isMobilePhoneAndFixedPhone(tel)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入正确的联系方式!");
			}
		}
		
		SplRlPsnVO prdSplRlPsnVO = new SplRlPsnVO();
		prdSplRlPsnVO.setSplId(Long.valueOf(splId));
		prdSplRlPsnVO.setRlTypCd(rlTypCd);
		prdSplRlPsnVO.setRlNm(rlNm);
		prdSplRlPsnVO.setCertTypCd(certTypCd);
		prdSplRlPsnVO.setCertNo(certNo);
		prdSplRlPsnVO.setTel(tel);
		prdSplRlPsnVO.setRlRem(rlRem);
		
		return prdSplRlPsnVO;
	}
	
	/**
	 * 获取联系人请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private SplRlPsnVO getRequestParamForPrdSplRlPsnAdd(HttpServletRequest request)throws BaseException{
		SplRlPsnVO prdSplRlPsnVO = this.getRequestParamForPrdSplRlPsn(request);
		prdSplRlPsnVO.setCrtTm(new Date());
		prdSplRlPsnVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		return prdSplRlPsnVO;
	}
	
	/**
	 * 获取联系人请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private SplRlPsnVO getRequestParamForPrdSplRlPsnModify(HttpServletRequest request)throws BaseException{
		SplRlPsnVO prdSplRlPsnVO = this.getRequestParamForPrdSplRlPsn(request);
		prdSplRlPsnVO.setMdfTm(new Date());
		prdSplRlPsnVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return prdSplRlPsnVO;
	}

	/**
	 * 封装必输联系人信息
	 * @param voList
	 */
	private List<SplRlPsnVO> setSplRlPsnList(List<SplRlPsnVO> voList){
		//证件类型
		List<KeyValueVO> certTypCdList = this.splRlPsnService.searchCertTypCdList();
		//获取默认证件类型名称
		String defCodNm = "";
		for (KeyValueVO keyValueVO : certTypCdList) {
			if(keyValueVO.getKey().equals(SplInfoConstant.CODE_CERT_TYP_DEF_CD)){
				defCodNm = keyValueVO.getValue();
			}
		}
		//必填联系人类型
        List<SysDictionaryDTO> mustAddRlPsnTypCds = this.sysDictionaryApiService.searchGroupAll(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),DictionaryConstant.CODE_RL_TYP_CD);
        List<String> mustAddRlPsns = null ;
        if(CollectionUtils.isNotEmpty(mustAddRlPsnTypCds)){
            mustAddRlPsns = new ArrayList<>(mustAddRlPsnTypCds.size());
            for(SysDictionaryDTO dto : mustAddRlPsnTypCds){
                if(BaseConstant.IS_YESNO_NO == dto.getIsSysDef()){
                    continue;
                }
                mustAddRlPsns.add(dto.getCode());
            }
        }
		//联系人类型
		List<KeyValueVO> rlTypCDList = this.splRlPsnService.searchRlTypCdList();
		Map<String,SplRlPsnVO> map=new HashMap<String,SplRlPsnVO>();
		//查询出所有必输联系人信息
		if(null != rlTypCDList && rlTypCDList.size()>0) {
			for (KeyValueVO keyValueVO : rlTypCDList) {
				if(!keyValueVO.getKey().equals(SplInfoConstant.SPL_RL_TYP_CD_ACTUAL_2)
                        && (CollectionUtils.isNotEmpty(mustAddRlPsns) && mustAddRlPsns.contains(keyValueVO.getKey()) || CollectionUtils.isEmpty(mustAddRlPsns))) {
					SplRlPsnVO vo = new SplRlPsnVO();
					vo.setRlTypCd(keyValueVO.getKey());
					vo.setRlTypCdNm(keyValueVO.getValue());
					vo.setCertTypCd(SplInfoConstant.CODE_CERT_TYP_DEF_CD);
					vo.setCertTypCdNm(defCodNm);
					vo.setIsDel(BaseConstant.IS_YESNO_NO);
					vo.setIsDefault(BaseConstant.IS_YESNO_YES);
					map.put(keyValueVO.getKey(), vo);
				}
			}
		}
		//判断修改的联系人信息中是否存在必输的联系人
		if(null != voList && voList.size()>0){
			//循环将已经存在的vo信息
			for (SplRlPsnVO splRlPsnVO : voList) {
				//如果存在必输联系人，将必输Map中联系人去除
				if(map.containsKey(splRlPsnVO.getRlTypCd())){
					map.remove(splRlPsnVO.getRlTypCd());
				}
			}
		}else{//新增时或修改时无联系人信息，创建联系人
			voList=new ArrayList<SplRlPsnVO>();
		}
		//将去除重复后的必输联系人添加到联系人列表中
		if(null != map && map.size()>0){
			for (Map.Entry<String, SplRlPsnVO> entry : map.entrySet()) {
				voList.add(entry.getValue());
			}
		}
		return voList;
	}
	
	
}

